/*
 * @Description: 
 * @Author: rendc
 * @Date: 2025-10-21 09:11:25
 * @LastEditors: rendc
 * @LastEditTime: 2025-10-21 15:01:22
 */
// 数据类型转换
var flag = true;
console.log('🤡 CC - flag.toString():', flag.toString());
console.log('🤡 CC - flag.toString():' + flag.toString());
console.log("字符串" + 123);
console.log("字符串", 123);
var num = 123;
console.log('🤡 CC - num.toString():' + num.toString());

console.log('🤡 CC - typeof flag.toString():', typeof flag.toString());
console.log('🤡 CC - typeof num.toString():', typeof num.toString());

var s = "string";
console.log('🤡 CC - s.toString():', s.toString());

var u = undefined;
// console.log('🤡 CC - u.toString():', u.toString());

var n = null;
// console.log('🤡 CC - n.toString():', n.toString());


var num = 0b01; // 1
console.log('🤡 CC - num.toString(2):', num.toString(2));
var num = 1000; // 1000
console.log('🤡 CC - num.toString(16):', num.toString(16));

var num = 123;
"123" - num
console.log(`🤡 CC - "123"-num:`, "123" - num);
console.log('🤡 CC - -num:', -num);

Boolean("hello") // true
Boolean("false") // true
console.log('🤡 CC - Boolean(undefined) :', Boolean(undefined));
console.log('🤡 CC - Boolean(null) :', Boolean(null));

console.log(`🤡 CC - Number("+123.1"):`, Number("+123.1"));
console.log(`🤡 CC - Number("1*123.1"):`, Number("1*123.1"));
console.log(`🤡 CC - Number("00.11"):`, Number("00.11"));
console.log(`🤡 CC - Number("0o11"):`, Number("0o11"));
console.log(`🤡 CC - Number("123abc"):`, Number("123abc"));
var num = 0o11;
// var num = 011;

console.log(`🤡 CC - Number(null):`, Number(null));
console.log('🤡 CC - parseInt(10):', parseInt(10));
console.log('🤡 CC - parseInt(10.1):', parseInt(10.1));
console.log('🤡 CC - parseInt("10.1"):', parseInt("10.1"));
console.log('🤡 CC - parseInt("10.1"):', parseInt("10.1"));
console.log('🤡 CC - parseInt("10.1"):', parseInt("10.1"));
console.log('🤡 CC - parseInt("19.9-10.1"):', parseInt("19.9-10.1"));
console.log('🤡 CC - parseInt(19.9-10.1):', parseInt(19.9 - 10.1));
console.log('🤡 CC - parseInt(0o11):', parseInt(0o11));
console.log('🤡 CC - parseInt(0x11):', parseInt(0x11));
console.log('🤡 CC - parseInt(""):', parseInt(""));
console.log('🤡 CC - parseInt():', parseInt());
console.log(`🤡 CC - Number(""):`, Number(""));
console.log(`🤡 CC - Number():`, Number());

console.log('🤡 CC - parseInt("1+2.3"):', parseInt("1+2.3"));
console.log('🤡 CC - parseInt("123abc"):', parseInt("123abc"));
console.log('🤡 CC - parseInt("abc123"):', parseInt("abc123"));
console.log('🤡 CC - parseInt(false):', parseInt(false));
console.log('🤡 CC - parseInt(true):', parseInt(true));


console.log('🤡 CC - paresInt(1.1):', parseInt(1.1));
console.log('🤡 CC - paresFloat(1.1):', parseFloat(1.1));
console.log('🤡 CC - paresInt("0x11"):', parseInt("0x11"));
console.log('🤡 CC - paresFloat("0x11"):', parseFloat("0x11"));


"23" + 4
console.log(`🤡 CC - "23"+4:`, "23" + 4);
1 + "23"
console.log(`🤡 CC - 1 + "23":`, 1 + "23");
console.log(`🤡 CC - +"23":`, +"23");
console.log(`🤡 CC - +null:`, +null);
console.log(`🤡 CC - +undefined:`, +undefined);


// 结果是 true 还是 false
console.log('🤡 CC - 1 == 1:', 1 == 1); // true
console.log('🤡 CC - true == true:', true == true); // true
console.log('🤡 CC - true == !true:', true == !true); // false

console.log('🤡 CC - [] == ![] :', [] == ![]);
// console.log('🤡 CC - [] === ![] :', [] === ![]);

// [] -> boolean 
// Boolean([])
console.log('🤡 CC - Boolean([]):', Boolean([]));
console.log('🤡 CC - Boolean(![]):', Boolean(![]));
// [].toString() "" Boolean("") false
console.log('🤡 CC - [].toString():', [].toString());
// Number("") 0
// Number(false) 0
// 0 == 0 true
console.log('🤡 CC - Number(false):', Number(false));
console.log(`🤡 CC - Number(""):`, Number(""));
console.log(`🤡 CC - Boolean(""):`, Boolean(""));


var a = [] + {}
console.log('🤡 CC - [] + {}:', [] + {});
var b = {} + []
console.log(`🤡 CC - {} + [] :`, {} + []);
console.log('🤡 CC - a == b:', a == b);
console.log('🤡 CC - a === b:', a === b);


var obj = {
  name: "zs",
  age: 18,
  toString: function () {
    return this.name + ":" + this.age;
  },
  valueOf: function () {
    return 100;
  },
}
var obj1 = {

}
// Boolean(obj);
console.log('🤡 CC - Boolean(obj):', Boolean(obj));
console.log('🤡 CC - Boolean(obj1):', Boolean(obj1));
var person = null;
// person = 一个网络请求的返回值
if (person) {
  // 判断是否赋值成功
}
obj.toString()
console.log('🤡 CC - obj.toString():', obj.toString());
// Number(obj)
console.log('🤡 CC - Number(obj):', Number(obj));

// sayHello1(); // 此处不能使用
var sayHello1 = function () {
  console.log("Hello1");
}
sayHello1(); // var 关键字声明的函数 要在声明赋值之后使用

sayHello2(); // function声明的函数会有 声明提升的效果
// 所以可以在函数声明之前使用。
function sayHello2 () {
  console.log("Hello2");
}
sayHello2(); // 声明之后也可以使用

function sum (a, b) {
  return a + b;
  // console.log(a + b);
}

var result = sum(1, 2);
console.log('🤡 CC - result:', result);

var result = sum(1, "2");
console.log('🤡 CC - result:', result); // 12


// var a = 3;
var result = sum;
console.log('🤡 CC - result:', result); // [Function: sum]
// result(1,2)
console.log('🤡 CC - result(1,2):', result(1, 2));

// 请声明一个不限参数个数的求和方法
function sum2 () {
  // 内部属性
  // console.log(arguments);
  var result = 0;
  for (const key in arguments) {
    const element = arguments[key];
    // console.log('🤡 CC - sum2 - element:', element);
    result += element;
  }
  console.log('🤡 CC - sum2 - result:', result);
  // console.log(a + b + c);
}

sum2(1, 1, 1)
sum2(1)
sum2(1, 1)
sum2(1, 1, 1, 1)

// this
console.log('🤡 CC - this:', this);

function foo () {
  var a = 10;
  console.log('🤡 CC - foo - a:', a);
}
foo();

(function () {
  var a = 10;
})();

var sum3 = (function (a, b) {
  return a + b;
})(1, 2);
console.log('🤡 CC - sum3:', sum3);

// (1 + 1) * 2